//  快递回收商家；获取定案列表
orderStatus = '130';
//  快递商家，获取索引值
window.onload = function () {
    //  获取需要索引的选手
    var ebtns = document.getElementById("expressBtns").getElementsByTagName("button");
    var divs = document.getElementById("divs").getElementsByTagName("div");
    for (var i = 0; i < ebtns.length; i++) {
        ebtns[i].index = i; //自定义属性，用于关联下面的大盒子
        ebtns[i].onclick = function () {

            for (var j = 0; j < ebtns.length; j++) {
                //把所有的button清空类名 （注意，是先清空再添加）
                ebtns[j].className = "";
            }
            //点击的那个盒子添加指定类名
            this.className = "color";
            for (var i = 0; i < divs.length; i++) {
                //先让底下的div全部隐藏
                divs[i].style.display = "none";
            }
            //然后给当前所点击按钮相关联的盒子添加指定属性
            console.log(this.index)
            if (this.index == 0) {
                orderStatus = '130';
            } else if (this.index == 1) {
                orderStatus = '131';
            } else if (this.index == 2) {
                orderStatus = '170';
            } else if (this.index == 3) {
                orderStatus = '180';
            } else if (this.index == 4) {
                orderStatus = '100,191,192';
            }
            $('#listStrId').html(); // 局部刷新一下页面
            console.log(orderStatus)
            expressGetOrder();
        }
    }
}

function skipLogistics() {
    document.location.href = '../sellUpstream/addLogistics.html'
}

//  快递回收商家；获取相应的列表
function expressGetOrder() {
    var newTime = timeAll();
    var timestamp = 'orderStatus:' + orderStatus + 'BM' + 'pageNum:' + 1 + 'BM' + 'pageSize:' + 100 + 'BM' + 'timeStamp:' + newTime + 'BM';
    var signs = md5(timestamp);
    signs = signs.toUpperCase();
    $.ajax({
        type: "get",
        url: webUrl + "orderProcessing/getOrders",
        data: {
            "orderStatus": orderStatus,
            "pageNum": 1,
            "pageSize": 100,
            "sign": signs,
            "timeStamp": newTime
        },
        dataType: "JSON",
        async: false,
        success: function (data) {
            console.log(data);
            $('#listStrId').html(data);
            if (data.status == 200) {
                var listAll;
                var no = {nameNo: '未知', prieNo: '0'};
                for (var i = 0; i < data.data.length; i++) {
                    var item = data.data[i];
                    listAll = '<li class="liDiv" onclick="textsss()">' +
                        '<div class="heardDiv">' +
                        '<div>回收方式：' + item.recycleMethod +
                        '</div>' +
                        '<div>' + (orderStatus == "101" ? "新订单" : orderStatus == "110" ? "待审核" : "已取消") + '</div>' +
                        '</div>' +
                        '<div class="heardDiv">' +
                        '<div>' + (item.name != '' ? item.name : no.nameNo) +
                        '</div>' +
                        '<a class="call" href="tel:' + item.telephone + '">' + '<img class="imgStr" src="../imges/iphone.png">' + '</a>' +
                        '</div>' +
                        '<div class="heardDiv">' + item.address +
                        '</div>' +
                        '<p class="fuMenu">估计单 </p>' +
                        '<div class="divShou">收起</div>' +
                        '<img class="xiala" src="../imges/xia@1x.png"/>' +
                        '<div class="div1">';
                    var productName = '<div class="zcd">' + '<div>' + '名称' + '</div>' + '<div>' + (item.productDetail.productName != '' ? item.productDetail.productName : no.nameNo) + '</div>' + '</div>';
                    listAll = listAll + productName;

                    for (var j = 0; j < item.productDetail.attrList.length; j++) {
                        var attrListItem = item.productDetail.attrList[j];
                        var typeStr = '<div class="zcd" id=' + attrListItem.attrCategoryId + '>' +
                            '<div>' + attrListItem.attrCategoryName +
                            '</div>' +
                            '<div>' + attrListItem.attrName +
                            '</div>' +
                            '</div>';
                        listAll = listAll + typeStr;
                    }
                    if (orderStatus == '130') {
                        listAll = listAll + '<div class="guJiaDiv">靓机回收价：' + item.tiptopPrice + '元' +
                            '</div>' + '<div class="YuGu">预估</div>';
                    } else {
                        listAll = listAll + '';
                    }
                    for (var k = 0; k < item.productDetail.problemList.length; k++) {
                        var problemListItem = item.productDetail.problemList[k];
                        var productStr = '<div class="zcd" id="zcd10">' +
                            '<div>' + (problemListItem.problemCategoryName != '' ? problemListItem.problemCategoryName : no.nameNo) +
                            '</div>' +
                            '<div>' + (problemListItem.problemName != '' ? problemListItem.problemName : no.nameNo) +
                            '</div>' +
                            '<div>' + '-' + (problemListItem.problemPrice != '' ? problemListItem.problemPrice : no.prieNo) + '元' +
                            '</div>' +
                            '</div>';
                        listAll = listAll + productStr;
                    }

                    listAll = listAll + '</div>' +
                        '<div class="downDiv">' +
                        '<div class="downDiv2">' +
                        '<div>本单预计估价：</div>' +
                        '<div>' + (item.userPrice != '' ? item.userPrice : no.prieNo) + '元' +
                        '</div>' +
                        '</div>' +
                        '<div class="orderDiv">' +
                        '<div>下单时间：' + item.createDate +
                        '</div>' +
                        '<div>单号：' + item.orderNum +
                        '</div>' +
                        '</div>';
                    var buttonClickList;
                    if (orderStatus == '130') {
                        buttonClickList = '<div class="downDiv3">' +
                            '<div class="item" onclick=receiveClick(\"' + item.orderId + '\")>到货</div>' +
                            '<div class="item" onclick=refuseClick(\"' + item.orderId + '\")>未到货</div>' +
                            '</div>';
                    } else if (orderStatus == '131') {
                        buttonClickList = '<div class="downDiv3">' +
                            '<div class="item" onclick=adoptClick(\"' + item.orderId + '\")>审核通过</div>' +
                            '<div class="item" onclick=NOadoptClick(\"' + item.orderId + '\")>审核不通过</div>' +
                            '</div>';
                    } else if (orderStatus == '170') {
                        buttonClickList = '<div class="downDiv3">' +
                            '<div class="item" onclick=messageDeal(\"' + item.orderId + '\")>通知用户</div>' +
                            '</div>';
                    } else if (orderStatus == '180') {
                        buttonClickList = '<div class="downDiv3">' +
                            
                            // 业务没行清楚
                            '<div class="item" onclick=skipLogistics(\"' + item.orderId + '\")>填写退货快递</div>' +
                            '</div>';
                    } else {
                        buttonClickList = '';
                    }
                    listAll = listAll + buttonClickList + '</div>' +
                        '</li>';
                    $('#listStrId').append(listAll);
                }
            } else if (data.status == 300) {
                document.location.href = '../html/login.html';
            } else if (data.status == 500) {
                alert(data.msg)
            }
        }
    })

}

// 新订单 到货  ------
function AOG(id) {
    var newTime = timeAll();
    var timestamp = 'orderId:' + id + 'BM' + 'timeStamp:' + newTime + 'BM';
    var signs = md5(timestamp);
    signs = signs.toUpperCase();
    $.ajax({
        type: "get",
        url: webUrl + "orderProcessing/operateOrde",
        data: {
            "orderId": id,
            "sign": signs,
            "timeStamp": newTime
        },
        dataType: "JSON",
        async: false,
        success: function (data) {
            console.log(data);
            if (data.status == 200) {
                // 点击到货自条状到待审核；跳转到对应的新订单单，然后那个订单染色加深（个人建议；如何实现???）
                alert('货物已经收到');
                expressGetOrder();
            } else if (data.status == 300) {
                document.location.href = '../html/login.html';
            } else {
                alert(data.msg);
            }
        }
    })

}

//  新订单 未到货
function unAOG(id) {
    var newTime = timeAll();
    var timestamp = 'orderId:' + id + 'BM' + 'timeStamp:' + newTime + 'BM'+'orderStatus:'+ 103 + 'BM';
    var signs = md5(timestamp);
    signs = signs.toUpperCase();
    $.ajax({
        type: "get",
        url: webUrl + "orderProcessing/operateOrde",
        data: {
            "orderId": id,
            "sign": signs,
            "timeStamp": newTime
            'orderStatus': 103,
        },
        dataType: "JSON",
        async: false,
        success: function (data) {
            console.log(data);
            if (data.status == 200) {
                // 点击到货自条状到待审核；跳转到对应的新订单单，然后那个订单染色加深（个人建议；如何实现???）
                alert('货物已经收到');
                expressGetOrder();
            } else if (data.status == 300) {
                document.location.href = '../html/login.html';
            } else {
                alert(data.msg);
            }
        }
    })
}

//  待交易；发送通知给用户；用户确认交易
function messageDeal(id) {
    var newTime = timeAll();
    var timestamp = 'timeStamp:' + newTime + 'BM';
    var signs = md5(timestamp);
    signs = signs.toUpperCase();
    $.ajax({
        type: 'get',
        url: webUrl3 + 'store/orderProcessing/remindUserVerifyOrder',
        data: {
            'timeStamp': newTime,
            'sign': signs,
        },
        dataType: 'JSON',
        async: false,
        success: function (data) {
            console.log(data)
            // 200 弹框；提示；已经通知用具确认交易
        }
    })
}

//  填写物流消息解耦   -----
function writeLogistics() {
    var newTime = timeAll();
    var timestamp = 'timeStamp:' + newTime + 'BM';
    var signs = md5(timestamp);
    signs = signs.toUpperCase();
    $.ajax({
        type: 'get',
        url: webUrl3 + ' store/orderProcessing/remindUserVerifyOrder',
        data: {
            'timeStamp': newTime,
            'sign': signs,
        },
        dataType: 'JSON',
        async: false,
        success: function (data) {
            console.log(data)
            // 200 弹框；提示；已经通知用具确认交易
        }
    })
}

